<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Weather Example: Watch Simple Version</title>
    <!-- import Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
  </head>
  <body>
    <div id="root">
      <h2>今天天气很{{info}}</h2>
      <button @click="changeWeather">点击切换</button>
    </div>
  </body>

  <script type="text/javascript">
    Vue.config.productionTip = false; // 阻止vue在启动时生成生产提示。
    const vm = new Vue({
      el: "#root",
      data: {
        isHot: true,
      },
      computed: {
        info() {
          return this.isHot ? "炎热" : "凉爽";
        },
        numberA() {
          return this.numbers.a;
        },
      },
      methods: {
        changeWeather() {
          this.isHot = !this.isHot;
        },
      },
      watch: {
        // 正常写法
        // isHot: {
        // //   immediate: true,  //  初始化时让handler调用一下
        // //   deep: true,       // 深度监视
        //   handler(newValue, oldValue) {
        //     console.log("info is modified", newValue, oldValue);
        //   },
        // },
        
        // 简写
        isHot(newValue, oldValue){
            console.log('is hot changed')
        }
      },
    });
    // 完整写法
    // vm.$watch('isHot',{
    //         immediate: true,
    //         handler(newValue, oldValue){
    //             console.log('isHot $watch', newValue, oldValue)
    //         }
    //     })

    //简写
    vm.$watch('isHot',function(newValue, oldValue){
        console.log('isHot $watch', newValue, oldValue)
    })
  </script>
</html>
